package com.zmht.specedu.senate.dao.impl;

import java.util.List;

import com.zmht.specedu.frame.dao.impl.GenericDao;
import com.zmht.specedu.frame.model.PageInfoModel;
import com.zmht.specedu.frame.util.StringUtils;
import com.zmht.specedu.senate.dao.ITeacherDao;
import com.zmht.specedu.vo.Teacher;

/**
 * @author ������ 2009��4��22
 * ��ʦ����
 */

public class TeacherDaoImpl extends GenericDao<Teacher,Integer> implements ITeacherDao {
	
	public TeacherDaoImpl() {
		super(Teacher.class);
	}
	
	public PageInfoModel getList(PageInfoModel pageInfo, String tname,String zeRenType) throws Exception {
String hql="";
		
		if(tname==null||tname.trim().equals(""))/**查询时，未输入教师名*/
			tname="";
		if(zeRenType==null||zeRenType.trim().equals(""))/**查询时，未选择 责任类别时，默认所有*/
			zeRenType="";
		if(zeRenType.equals("") || zeRenType.equals("所有"))/**查询时，没有选择责任类型*/
			hql="from Teacher a where 1=1 ";
		else			
		    hql="from Teacher a where a.zeRenType = '"+zeRenType+"'";				
		if(StringUtils.isNotEmpty(tname)){/**输入有教师名*/
			hql+= "and a.tname like '%"+tname+"%' ";
		}
		hql+="  order by a.teacherId desc";
		System.out.println("thql=="+hql);
		return this.findByHQL(hql, pageInfo);
	}

	public boolean isValidUsername(String username) throws Exception {
		boolean flag=false;
		List list=this.findByHQL("from Teacher a where a.tuserName='"+username+"'");
		if(list.size()==0)
			flag=true;
		return flag;
	}

	public List getList() throws Exception {		
		return this.findByHQL("from Teacher a order by a.teacherId");
	}

	public Teacher findTeacherById(int id) throws Exception {		
		return this.findByHQL("from Teacher a where a.teacherId="+id).get(0);
	}

	

	
	
}
